package com.zeroone.star.publish.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zeroone.star.publish.entity.Contact;
import com.zeroone.star.publish.entity.VolunteerRegistrations;
import com.zeroone.star.publish.mapper.ContactMapper;
import com.zeroone.star.publish.mapper.VolunteerRegistrationsMapper;
import com.zeroone.star.publish.service.IContactService;
import com.zeroone.star.publish.service.IVolunteerRegistrationsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @program: car-time-bank
 * @description:
 * @author: car
 * @create: 2024-04-10 16:10
 **/
@Service
public class RegistrationServiceImpl extends ServiceImpl<VolunteerRegistrationsMapper, VolunteerRegistrations> implements IVolunteerRegistrationsService {


    @Autowired
    private VolunteerRegistrationsMapper registrationsMapper;

    @Override
    public Integer addRegistration(Integer userId, Integer volunteerId) {
        VolunteerRegistrations registrations = new VolunteerRegistrations();
        registrations.setRegistrationDate(new Date());
        registrations.setUserId(userId);
        registrations.setVolunteerId(volunteerId);
        return  registrationsMapper.insert(registrations);

    }

    @Override
    public ArrayList<Integer> selectAllEnrollVolunteer(Integer volunteerId) {
        QueryWrapper<VolunteerRegistrations> wrapper = new QueryWrapper<>();
        wrapper.eq("volunteer_id",volunteerId);
        List<VolunteerRegistrations> volunteerRegistrations = registrationsMapper.selectList(wrapper);
        ArrayList<Integer> userIdList = new ArrayList<>();
        for (int i = 0; i < volunteerRegistrations.size(); i++) {
            userIdList.add(volunteerRegistrations.get(i).getUserId());
        }
        return userIdList;
    }
}
